﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenSoftStore.BusinessLogic.Common;
using OpenSoftStore.BusinessLogic.Member;
using OpenSoftStore.Client.Common;
using OpenSoftStore.Orm.Model;

namespace OpenSoftStore.Client.UIL.ManageMember.Info
{
    public partial class Remind : UserControl
    {
        private static Remind instance;
        public MemberLogic MemberBll;
        public T_Member Member;
        public ComboLogic ComboBll;
        public static Remind Instance
        {
            get { return instance ?? (instance = new Remind()); }
        }

        public Remind()
        {
            InitializeComponent();
            MemberBll = new MemberLogic();
            Member = new T_Member();
            ComboBll = new ComboLogic();
            SPACommon.SetUiStyle(this);

            cmbContact.DisplayMember = "DisplayText";
            cmbContact.ValueMember = "Value1";
            cmbContact.DataSource = ComboBll.GetComboByBuzType("RemindState");

            dtpFrom.Value = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00");
            dtpTo.Value = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59");
        }

        public void GetReminds(T_Member member)
        {
            Member = member;
            btnSearch_Click(null, null);
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            var from = dtpFrom.Value;
            var to = dtpTo.Value;
            string state = cmbContact.Text;
            string whereStr = string.Format(" where  R.NextRemindTime between #{0}# and #{1}#  and R.State='{2}' and M.CardId='{3}'", from, to, state, Member.CardId);
            dgvRemind.DataSource = MemberBll.GetRemindView(whereStr);
        }

        private void btnSearch_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnSearch_Click(null, null);
            }
        }
    }
}
